With the following code i'm checking some modules for outgoing links over a specific link module. However the script doesn't set the wanted tag if the link module is not in the same folder as the module i want to set it in. That's pretty bad because the linkmodules are normally in another folder. Does anyone know the solution to this ?
string path_project = "*project*"
string path_cust_reqs = "*Path*"
const bool DISPLAY_VIEW = false
const int OFFSET = null
const int LENGTH = null
const bool MATCH_CASE = true
const bool REVERSE = false
bool dialog_has_next = false
void check_modules_listview(DB db) {
dialog_has_next = true
}
//necessary mini functions
#include <pkg/is_editable_module.dxl>
#include <pkg/outgoingLinkExplorer.dxl>
#include <pkg/ack_factory.dxl>
#include <pkg/get-item-count.dxl>
DB dialog_box_modules = null
DBE label_modules, db_modules_frame_main, db_modules_frame_listview, dialog_box_modules_list, dialog_box_modules_button_all, dialog_box_modules_button_none
DB dialog_box_links = null
DBE db_links_frame_main, label_links, dialog_box_links_list, db_links_frame_listview = null
DB progressAckDummy = null
const string LABEL_CONTENT_MAINFRAME = "Link Exploration"
const string LABEL_CONTENT_MODULES = "Choose all modules which shall be explored for outgoing links."
const string LABEL_CONTENT_LINK_MODULES = "Choose the link module which shall be explored for the searched linksets."
Skip link_module_names = create()
int modules_count = get_item_count("Formal")
string modules[modules_count]
int links_count = get_item_count("Link")
string link_modules[links_count]
void check_links_listview(DB db) {
int check_count = 0
int i; for(i = 0; i < sizeof(link_modules); i++) {
if(getCheck(dialog_box_links_list, i)) {
string linkModName = getColumnValue(dialog_box_links_list, i, 0)
put(link_module_names, linkModName, linkModName)
}
}
dialog_has_next = true
}
void select_all(DBE dbe) {
int i
for (i = 0; i < noElems(dialog_box_modules_list); i++) {
setCheck(dialog_box_modules_list, i, true)
}
}
void clear_all(DBE dbe) {
int i
for (i = 0; i < noElems(dialog_box_modules_list); i++) {
setCheck(dialog_box_modules_list, i, false)
}
}
void startProgressBar(string message, int progressMax) {
progressAckDummy = create("Processing..", styleCentered)
realize(progressAckDummy)
progressStart(progressAckDummy, message, "Initializing..", progressMax)
}
// get list of link modules
void get_link_modules_list() {
string linkModulesPath = "" fullName(current Project) "/01 - Linkmodules"
int listview_links_pos = 0
Item item
for item in project path_project do {
string item_type = type(item)
string item_path = fullName(item)
string item_name = name(item)
string item_description = description(item)
if(item_type == "Link") {
insert(dialog_box_links_list, listview_links_pos, item_name, iconNone)
link_modules[listview_links_pos] = item_path
listview_links_pos++
}
}
}
// get module list
void get_modules_list() {
int listview_modules_pos = 0
Module module
Item item
for item in project path_project do {
string item_type = type(item)
string item_path = fullName(item)
string item_name = name(item)
string item_description = description(item)
if(findPlainText(item_path, path_cust_reqs, OFFSET, LENGTH, MATCH_CASE, REVERSE) && item_type == "Formal") {
module = read(item_path, DISPLAY_VIEW)
string module_name = name(module)
string module_description = description(module)
insert(dialog_box_modules_list, listview_modules_pos, module_name, iconNone)
set(dialog_box_modules_list, listview_modules_pos, 1, module_description)
modules[listview_modules_pos] = item_path
listview_modules_pos++
}
}
}
//Gui with modules list
void modulesDialog(string projectName) {
*GUI PARAMETER*
}
//Gui with linkmodules list
void linkModulesDialog(string projectName) {
*GUI PARAMETER*
}
// check wether modules are opened in Exclusive Edit
bool checkEditable(string modules[]) {
bool allModulesAvailable = true
int j
for (j = 0; j < sizeof(modules); j++) {
if(getCheck(dialog_box_modules_list, j)) {
if(!isEditable(modules[j])) {
allModulesAvailable = false
}
}
}
return allModulesAvailable
}
// MAIN
void main() {
string projectName = name(current Project)
linkModulesDialog(projectName)
if(dialog_has_next) {
modulesDialog(projectName)
if(dialog_has_next) {
if(checkEditable(modules)) {
getUserInput() // Enter the name of the attribute you want to create
if(dialog_has_next){
if(attrName == "") {
infoBox("You didn't type in an attribute. Execution cancelled!")
}
else {
int j; for(j = 0; j < sizeof(modules); j++) {
if(getCheck(dialog_box_modules_list, j)) {
exploreLinks(modules[j], link_module_names) //creates attribute and fills it
}
}
makeAck("Finished")
}
}
else{
infoBox("Execution cancelled!")
}
} else {
makeAck("At least one of the selected modules could not be opened in edit mode")
}
}
}
}
main()
outgoinkLinkExplorer Function:
//main function of the tool
pragma runLim, 0
string attrName = ""
string dateTime = stringOf(today,"yyyyMMdd")
void closeCB(DB db){
dialog_has_next = true
release(db)
}
// Get the Input by the user how the attribute should be called
void getUserInput() {
DB db
DBE input
dialog_has_next = false
db = create("", styleCentered)
input = field(db, "Which attribute do you want to create?", "", 30, false)
ok(db, "OK", closeCB)
realize(db)
block(db)
//write user input in attrName
attrName = get(input)
//close window
destroy(db)
}
// creation of the wanted attribute
void createAttributes(){
Module m = current
AttrDef attrDef = create object type "Text" attribute attrName ""
}
Skip getOutgoingLinkContent(Object o, Skip linkModules) {
Skip linkedObjects = create()
string linkModule; for linkModule in linkModules do {
Link outlink; for outlink in o -> linkModule do {
ModName_ targetMod = target(outlink)
Module targetModuleDef = read(fullName(targetMod), false)
Object targetObj = target(outlink)
string objId = identifier(targetObj)
string moduleName = name(targetModuleDef)
string input = dateTime ": Requirement ID: " moduleName "_" objId
put(linkedObjects, objId, input)
}
}
return linkedObjects
}
//go through all selected modules and do the job
void iterateObjects(Module m, Skip linkModules) {
Object o; for o in m do {
Skip linkedObjects = create()
linkedObjects = getOutgoingLinkContent(o, linkModules)
string content = ""
if(linkedObjects != null) {
string entry; for entry in linkedObjects do {
if(content != "") {
content = content "\n"
}
content = content entry ""
}
}
string s = o.attrName
o.attrName = content "s" "\n" s
}
}
// main operation
void exploreLinks(string modulePath, Skip linkModuleNames) {
// HYPER PARAMS
bool DISPLAY_VIEW = false
bool SILENT = true
bool LOAD_STANDARD_VIEW = true
string linkMod; for linkMod in linkModuleNames do {
put(linkModuleNames, linkMod, fullName(current Project) "/01 - Linkmodules/")
}
// string linkModule = fullName(current Project) "/01 - Linkmodules/"
Module m = edit(modulePath, DISPLAY_VIEW, SILENT, LOAD_STANDARD_VIEW)
createAttributes()
iterateObjects(m, linkModuleNames)
//save(m)
//close(m, false)
}
1_H_5_R_7 - Mon Aug 06 09:59:33 EDT 2018 |